package com.erpoa.mapper;

import com.erpoa.entity.DetallEnutiy;
import com.erpoa.entity.PackMessageByFlatStorage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author liuxinyong
 * @Title: FlatStorageMapper
 * @ProjectName oaerp
 * @Description: TODO
 * @date 2021/1/1218:41
 */
@Mapper
public interface FlatStorageMapper {

    String wms_genfifono_fc(Map map);

    List<HashMap> querylistNo(@Param("listNo") String listNo);

    List<HashMap> querydetalt(@Param("listNo") String listNo);
    //条码
    PackMessageByFlatStorage querypckBarcode(@Param("message") PackMessageByFlatStorage packMessageByFlatStorage);
    //TODO
    List<PackMessageByFlatStorage> querypckpackMessage45(@Param("listNo") String listNo);

    List<PackMessageByFlatStorage> querypckpackMessage54(@Param("listNo") String listNo, @Param("palletNo") String palletNo);

    List<PackMessageByFlatStorage> querypckpackMessage(@Param("listNo") String listNo,@Param("palletNo") String palletNo);

    List<HashMap> querypckUn(@Param("prodNo") String prodNo,@Param("orgNo") String orgNo);

    List<HashMap> querylineId(@Param("listNo")  String listNo);

    PackMessageByFlatStorage querybyflat(@Param("pmbfs") PackMessageByFlatStorage packMessageByFlatStorage);

    String selectdetail(@Param("palletNo") String palletNo);

    String selectstk(@Param("palletNo") String palletNo);

    String selectqty(@Param("listNo") String listNo,@Param("orgNo") String orgNo,@Param("prodNo") String prod_no);

    String selecorgo(@Param("pckUn") String pckUn,@Param("orgNo") String orgNo,@Param("prodNo") String prod_no);

    String selectnum(@Param("orgNo") String orgNo,@Param("prodNo") String prod_no ,@Param("listNo") String listNo);

    String selectTmpQTy(@Param("lineId") String lineId,@Param("prodNo") String prod_no ,@Param("listNo") String listNo);

    int updatelist(@Param("listNo") String listNo);

    int updateline(@Param("listNo") String listNo,@Param("lineId") String lineId,@Param("prodNo") String prodNo,@Param("upTmpQty") String upTmpQty);

    String palletidx(@Param("listNo") String listNo,@Param("palletNo") String palletNo,@Param("orgNo") String orgNo);

    List<DetallEnutiy> selectdetall(@Param("listNo") String listNo, @Param("prodNo") String prodNo,DetallEnutiy detallEnutiy);

    double selectpckWgt(@Param("orgNo") String orgNo,@Param("prodNo") String prod_no ,@Param("pckUn") String pckUn);

    String selectGroupid();

    String Listchar(@Param("listNo") String listNo);

    int insertDETAIL(@Param("pack") PackMessageByFlatStorage packMessageByFlatStorage,@Param("data") DetallEnutiy detallEnutiy,@Param("palletidx") String palletidx,
                     @Param("qty1") String qty1,@Param("pckWgt2") String pckWgt2,@Param("fifono1") Object fifono1,@Param("listchar") String listchar);

    int insertorder(@Param("pack1") PackMessageByFlatStorage packMessageByFlatStorage,@Param("data") DetallEnutiy detallEnutiy,@Param("palletidx") String palletidx,
                    @Param("qty1") String qty1,@Param("pckWgt2") String pckWgt2,@Param("fifono1") Object fifono1,
                    @Param("Groupid") String Groupid,@Param("listchar") String listchar);
    int insertStk(@Param("pack1") PackMessageByFlatStorage packMessageByFlatStorage,@Param("data") DetallEnutiy detallEnutiy,@Param("palletidx") String palletidx,
                  @Param("qty1") String qty1,@Param("pckWgt2") String pckWgt2,@Param("fifono1") Object fifono1);

    List<HashMap> selectorgo(@Param("orgNo") String orgNo,@Param("prodNo") String prod_no,@Param("pckUn") String pckUn);

    int fifono1(@Param("listNo") String listNo,@Param("lineId") String lineId,@Param("palletNo") String palletNo);
    String fifono(@Param("listNo") String listNo,@Param("lineId") String lineId,@Param("palletNo") String palletNo);

    String selectDealQty(@Param("listNo") String listNo,@Param("palletNo") String palletNo);

    int updateWmsInLine1(@Param("listNo") String  listNo,@Param("lineId") String lineId,@Param("pack") PackMessageByFlatStorage packMessageByFlatStorage,@Param("tmpQty2") String tmpQty2);

    String selectPallet(@Param("listNo") String listNo,@Param("lineId") String lineId,@Param("palletNo") String palletNo);

    String selectcountPallet(@Param("listNo") String listNo,@Param("lineId") String lineId);

    int deleteWMS_STK(@Param("fifono") String fifono);

    int deleteWMS_STK_ORDER(@Param("listNo") String listNo,@Param("lineId") String lineId,@Param("fifono") String fifono);

    int deleteWMS_IN_DETAIL(@Param("listNo") String listNo, @Param("lineId") String lineId, @Param("fifono") String fifono);

    int countnum(@Param("listNo") String listNo, @Param("lineId") String lineId,@Param("prodNo") String prodNo);

    int updatewmsInline(@Param("listNo") String  listNo,@Param("lineId") String lineId,@Param("pack") PackMessageByFlatStorage packMessageByFlatStorage);

    int updatewmsInline2(@Param("listNo") String  listNo,@Param("lineId") String lineId,@Param("pack") PackMessageByFlatStorage packMessageByFlatStorage);

    int updatewmsInlist(@Param("listNo") String  listNo,@Param("pack") PackMessageByFlatStorage packMessageByFlatStorage);
    int updatewmsInlist1(@Param("listNo") String  listNo,@Param("pack") PackMessageByFlatStorage packMessageByFlatStorage);

    int upadtedetalt(@Param("listNo") String  listNo,@Param("lineId") String lineId,@Param("pack") PackMessageByFlatStorage packMessageByFlatStorage,@Param("pallet") int pallet);

    List<PackMessageByFlatStorage> querywmsInline(@Param("listNo") String listNo);
//TODO

    int selectlinecount1(@Param("palletNo") String palletNo);

    int selectlinecount2(@Param("palletNo") String palletNo);

    Integer pckQty(@Param("orgNo") String orgNo,@Param("prodNo") String prod_no,@Param("pckUn") String pckUn);
    Integer pltcount(@Param("orgNo") String orgNo,@Param("prodNo") String prod_no,@Param("pckUn") String pckUn);


    int wmsInList(@Param("listNo") String listNo);

    int countflag1(@Param("listNo") String listNo);
    int countflag2(@Param("listNo") String listNo , @Param("lineId") String lineId);

    int number1(@Param("listNo") String listNo , @Param("lineId") String lineId);


    //-----------------------------------------------

    @Select(" select STATUS_CTR  from WMS_IN_LIST t where LIST_NO='MGGI12100000004' and STATUS_CTR >= 14 and STATUS_CTR<90 ")
    String checkHasGroupByPalletNo(String palletNo);

    @Select(" select t.LIST_NO listNo,t.LINE_ID lineId,t.prod_no prodNo,t2.prod_name prodName,QTY Qty,SRC_QTY_DESC srcQtyDesc," +
            "t.pallet_no palletNo,t.fifo_no fifoNo,t.un un " +
            " from WMS_IN_LIST t1 " +
            " left join  WMS_IN_DETAIL t  " +
            " on t.list_no=t1.list_no  " +
            " LEFT JOIN LMS_PROD t2  " +
            " on t.prod_no=t2.prod_no and t.org_no=t2.org_no " +
            " where   t.PALLET_NO=#{palletNo} and   t1.STATUS_CTR >= 14 and t1.STATUS_CTR<90 ")
    PackMessageByFlatStorage selectDetailByPalletNo(String palletNo);

    @Select("   select count(*) from  " +
            "WMS_IN_LIST t " +
            "left join WMS_IN_DETAIL t1   " +
            "on t.list_no=t1.list_no  " +
            "where t1.PALLET_NO=#{palletNo} and t1.fifo_sts_ctr=0  and t.STATUS_CTR<>90 ")
    int countdetailByPalletNo(@Param("palletNo") String palletNo);

    @Select(" select BIN_AVAILABLE_PALLET from WMS_BIN where BIN_CODE=#{binCode} ")
    Integer queryBinByBarCode(String binCode);

    //select distinct  nvl(a.inhibit_in_flg, 'n') as inhibit_in_flgfrom wms_bin a where  bin_code = '2d0200101'  if inhibit_in_flg ='y'  then   报错
    @Select(" select distinct  nvl(a.inhibit_in_flg, 'n') as inhibitinflg from wms_bin a where  bin_code = #{binCode} ")
    String inhibit_in_flgfrom(String binCode);

//    @Select(" select count(*) from WMS_STK where BIN_CODE=#{binCode} ")
//    int queryStkByBarCode(String binCode);

    String callWMS_ASRS_FINISH_I_1_FC(Map param);

    @Select(" select count(*) from WMS_STK t " +
            " where t.PALLET_NO=#{palletNo} and ONWAY_CTR =0  ")
    int countStkByPalletNo(String palletNo);

    //todo cjm and Src_area_no not in ('ASRS')
 /*   @Select(" SELECT distinct Src_area_no NAME FROM WMS_OUT_DETAIL where FIFO_STS_CTR=90  and list_no in " +
            " (select list_no from wms_out_list where pick_date = to_date(#{pickDate},'yyyy-MM-dd') and Src_area_no not in ('ASRS')  and  STATUS_CTR='34' )  ")*/
   /* @Select(" SELECT   t.area_no NAME FROM WMS_OUT_DETAIL t where  exists  " +
            " (select list_no from wms_out_list t1 where pick_date = to_date(#{pickDate}, 'yyyy-MM-dd') and t1.list_no=t.list_no and STATUS_CTR in('32', '34') )   "+
            " and  FIFO_STS_CTR = 90 and area_no <>'ASRS'   group by t.area_no ")*/
    List<HashMap> selectAreaListByParam(String pickDate);
    //todo cjm

 /*   @Select(" select distinct t.cust_no CODE,t2.cust_name NAME from WMS_OUT_LIST t " +
            "left join  " +
            "WMS_OUT_DETAIL t1 on t.list_no=t1.list_no  " +
            "left join LMS_ORG_CUST t2 on t.cust_no=t2.cust_no and t.org_no=t2.org_no " +
            " where  PICK_DATE=to_date(#{packMessage.pickDate},'yyyy-MM-dd') and  SRC_AREA_NO = #{packMessage.srcAreaNo} and t.STATUS_CTR in ('32' ,'34')  " +
            "  and t.cust_no is not null "
    )*/
  /*  @Select("  select t.cust_no CODE,t2.sname NAME from WMS_OUT_LIST t  " +
            " left join   " +
            "WMS_OUT_DETAIL t1 on t.list_no=t1.list_no  " +
            "left  join LMS_ORG_CUST t2 on  t.org_no=t2.org_no and  t.cust_no=t2.cust_no " +
            " where  PICK_DATE=to_date(#{packMessage.pickDate},'yyyy-MM-dd') and  AREA_NO = #{packMessage.srcAreaNo} and t.STATUS_CTR in ('32' ,'34') and t2.cust_no is not null  " +
            "  GROUP BY t.cust_no,t2.sname "
    )*/
    List<HashMap> selectSnameListByParam(@Param("packMessage") PackMessageByFlatStorage packMessage);


    List<PackMessageByFlatStorage> selectOutListBy(@Param("packMessage") PackMessageByFlatStorage packMessage);


    String selectProdByPackBarCode(@Param("packMessage") PackMessageByFlatStorage packMessage);


    List<PackMessageByFlatStorage> queryAsrsFinishList(@Param("packMessage") PackMessageByFlatStorage packMessage);


    String callWMSRSFINISHO2FC(Map param);


    List<PackMessageByFlatStorage> queryPrintData(@Param("packMessage") PackMessageByFlatStorage packMessage);

    int updateAutoPrint(@Param("packMessage") PackMessageByFlatStorage packMessage);
}
